#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN = 100;
int n, k;
string s[MAXN];

string dp[MAXN][MAXN];

bool cmp(string a, string b) {
    return a + b < b + a;
}
int main() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++)cin >> s[i];

    sort(s + 1, s + 1 + n, cmp);
    dp[n][1] = s[n];
    for (int i = n-1; i >= 1; i--) {
        for (int j = 1; j <= n-i+1; j++) {
            dp[i][j] = s[i] + dp[i + 1][j - 1];
            if (dp[i+1][j] != "" )
                dp[i][j] = min(dp[i + 1][j], s[i] + dp[i + 1][j - 1]);
        }
    }

    cout << dp[1][k] << endl;
    return 0;
}